<template>
	<component
		ref="element"
		:is="compName"
		:value="value"
		:item="item"
		:query="query"
		:relation="relation"
		:radio="radio"
		:disabled="item.disabled"
		:disabledRows="disabledRows"
		:filterable="filterable"
		:allow-create="allowCreate"
		:multiple="multiple"
		:action="action"
		:params="params"
		:crm-type="crmType"
		:counts="counts"
		@value-change="(data) => $emit('value-change', data)"
	/>
</template>

<script>
import {
	XhInput,
	XhTextarea,
	XhSelect,
	XhMultipleSelect,
	XhDate,
	XhDateTime,
	XhDateSelect,
	XhInputRange,
	XhFiles,
	XhEdit,
	XhMultSelect,
	XhSelectInput,
	XhInputUnit,
	XhTree,
	XhAddress,
	XhMince,
	XhInputCheck,
	XhDataPara,
	XhDataGroup
} from '@/components/createCom/index.js'

const xhDatatable = () => import('./XhDatatable.vue')

export default {
	props: [
		'xxx',
		'value',
		'index',
		'item',
		'query',
		'relation',
		'radio',
		'disabled',
		'filterable',
		'allow-create',
		'multiple',
		'action',
		'params',
		'crmType',
		'type',
		'subType',
		'disabledRows',
		'counts'
	],
	components: {
		XhInput,
		XhTextarea,
		XhSelect,
		XhMultipleSelect,
		XhDate,
		XhDateTime,
		XhDateSelect,
		XhInputRange,
		XhFiles,
		XhEdit,
		XhMultSelect,
		XhSelectInput,
		XhInputUnit,
		XhTree,
		XhAddress,
		XhMince,
		XhInputCheck,
		XhDataPara,
		XhDataGroup
	},
	computed: {
		/** 根据type 找到组件 */
		compName() {
			var { subType, type } = this
			if (type == 'address') {
				return 'xh-address'
			} else if (
				type == 'text' ||
				type == 'number' ||
				type == 'floatnumber' ||
				type == 'mobile' ||
				type == 'email'
			) {
				return 'xh-input'
			} else if (type == 'textarea') {
				return 'xh-textarea'
			} else if (
				type == 'select' ||
				type == 'business_status' ||
				type == 'brand'
			) {
				return 'xh-select'
			} else if (type == 'checkbox') {
				return 'xh-multiple-select'
			} else if (type == 'date') {
				return 'xh-date'
			} else if (type == 'datetime') {
				return 'xh-date-time'
			} else if (type == 'dateselect') {
				return 'XhDateSelect'
			} else if (type == 'inputrange') {
				return 'XhInputRange'
			} else if (type == 'user') {
				return 'xh-user-cell'
			} else if (type == 'structure') {
				return 'xh-structure-cell'
			} else if (type == 'file') {
				return 'xh-files'
			} else if (
				type == 'customerpersonal' ||
				type == 'contractpersonal' ||
				type == 'businesspersonal' ||
				type == 'relation' ||
				type == 'contacts' ||
				type == 'contract' ||
				type == 'customer' ||
				type == 'business' ||
				type == 'suppliercontacts' ||
				type == 'person' ||
				type == 'claim'
			) {
				return 'crm-relative-cell'
			} else if (type == 'payable') {
				// 被保险人 受益人
				return 'xh-relation'
			} else if (type == 'tablex') {
				return 'xh-tablex'
			} else if (type == 'category') {
				// 产品类别
				return 'xh-prouct-cate'
			} else if (type == 'business_type') {
				// 订单类别
				return 'xh-business-status'
			} else if (type == 'business_insure_type') {
				return 'xh-business-insure-type'
			} else if (
				type == 'product' ||
				type == 'program' ||
				type === 'product-solution'
			) {
				return 'xh-product'
			} else if (type == 'map_address') {
				return 'xh-customer-address'
			} else if (type == 'receivables_plan') {
				return 'xh-receivables-plan'
			} else if (type == 'wangEditor') {
				return 'xh-edit'
			} else if (type == 'group') {
				return 'xh-group'
			} else if (type == 'supplier') {
				return subType == 2 ? 'task-supplier' : 'crm-relative-cell'
			} else if (type == 'channel') {
				return 'task-supplier'
			} else if (type == 'multSelect') {
				return 'xh-mult-select'
			} else if (type == 'unit') {
				return 'xh-input-unit'
			} else if (type == 'selectinput') {
				return 'xh-select-input'
			} else if (type == 'stageplans') {
				return 'xh-install'
			} else if (type == 'datatable') {
				return 'xh-datatable'
			} else if (type == 'multTreeSelect') {
				return 'xh-tree'
			} else if (type == 'table') {
				return 'xh-static-table'
			} else if (type == 'mince') {
				return 'xh-mince'
			} else if (type == 'list') {
				return 'task-plan-fields'
			} else if (type == 'datagroup') {
				return 'xh-data-group'
			} else if (type == 'check-text') {
				return 'xh-input-check'
			} else if (type == 'data-para') {
				return 'xh-data-para'
			} else {
				return ''
			}
		}
	}
}
</script>

<style lang="scss" scoped="scoped"></style>
